# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'recovery.ui'
#
# Created: Mon Aug 11 17:53:18 2008
#      by: PyQt4 UI code generator 4.4.2
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui
from PyQt4 import *

class Ui_Dialog(object):
    def setupUi(self, Dialog, listv):
        Dialog.setObjectName("Dialog")
        Dialog.resize(689,457)
        
        model = QtGui.QDirModel()
        
        self.pushButton = QtGui.QPushButton(Dialog)
        self.pushButton.setGeometry(QtCore.QRect(530,420,141,23))
        self.pushButton.setObjectName("pushButton")
#        self.treeView = tree
#        self.treeView.setGeometry(QtCore.QRect(240,50,431,342))
        
        #self.treeView.show()
        
  #      self.treeView = QtGui.QTreeView(Dialog)
  #      self.treeView.setGeometry(QtCore.QRect(10,50,211,331))
#        self.treeView.setObjectName("treeView")
   #     self.treeView.setModel(model)
        
        self.pushButton_2 = QtGui.QPushButton(Dialog)
        self.pushButton_2.setGeometry(QtCore.QRect(10,420,171,23))
        self.pushButton_2.setObjectName("pushButton_2")
#        self.label = QtGui.QLabel(Dialog)
#        self.label.setGeometry(QtCore.QRect(280,420,281,16))
#        font = QtGui.QFont()
#        font.setPointSize(11)
#        font.setWeight(75)
#        font.setBold(True)
#        self.label.setFont(font)
#        self.label.setObjectName("label")
        self.line = QtGui.QFrame(Dialog)
        self.line.setGeometry(QtCore.QRect(10,400,661,16))
        self.line.setFrameShape(QtGui.QFrame.HLine)
        self.line.setFrameShadow(QtGui.QFrame.Sunken)
        self.line.setObjectName("line")
#        self.comboBox = QtGui.QComboBox(Dialog)
#        self.comboBox.setGeometry(QtCore.QRect(240,340,431,22))
#        self.comboBox.setObjectName("comboBox")
        self.label_2 = QtGui.QLabel(Dialog)
        self.label_2.setGeometry(QtCore.QRect(15,20,271,16))
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setWeight(75)
        font.setBold(True)
        self.label_2.setFont(font)
        self.label_2.setObjectName("label_2")
        
        self.listView = listv
        self.listView.setGeometry(QtCore.QRect(240,50,431,342))
        
        self.listView.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
        self.listView.setMovement(QtGui.QListView.Snap)
        self.listView.setProperty("isWrapping",QtCore.QVariant(True))
        self.listView.setViewMode(QtGui.QListView.IconMode)
        self.listView.setObjectName("listView")

        
        #self.listView = QtGui.QListView(Dialog)
        #self.listView.setModel(model)
        #self.listView.setViewMode(QtGui.QListView.IconMode)
        #self.listView.setGeometry(QtCore.QRect(240,50,431,301))
        #self.listView.setObjectName("listView")
        
        
        
        self.pushButton_3 = QtGui.QPushButton(Dialog)
        self.pushButton_3.setGeometry(QtCore.QRect(650,20,21,23))
        self.pushButton_3.setObjectName("pushButton_3")
        
 #       
        self.line_2 = QtGui.QFrame(Dialog)
        self.line_2.setGeometry(QtCore.QRect(213,50,20,341))
        self.line_2.setFrameShape(QtGui.QFrame.VLine)
        self.line_2.setFrameShadow(QtGui.QFrame.Sunken)
        self.line_2.setObjectName("line_2")
        self.label_3 = QtGui.QLabel(Dialog)
        self.label_3.setGeometry(QtCore.QRect(23,70,191,16))
        font = QtGui.QFont()
        font.setPointSize(9)
        font.setWeight(75)
        font.setBold(True)
        self.label_3.setFont(font)
        self.label_3.setObjectName("label_3")
        self.label_4 = QtGui.QLabel(Dialog)
        self.label_4.setGeometry(QtCore.QRect(23,275,191,16))
        font = QtGui.QFont()
        font.setPointSize(9)
        font.setWeight(75)
        font.setBold(True)
        self.label_4.setFont(font)
        self.label_4.setObjectName("label_4")
        self.label_5 = QtGui.QLabel(Dialog)
        self.label_5.setGeometry(QtCore.QRect(20,230,191,16))
        font = QtGui.QFont()
        font.setPointSize(9)
        font.setWeight(75)
        font.setBold(True)
        self.label_5.setFont(font)
        self.label_5.setObjectName("label_5")
        self.label_6 = QtGui.QLabel(Dialog)
        self.label_6.setGeometry(QtCore.QRect(23,120,171,16))
        font = QtGui.QFont()
        font.setPointSize(9)
        font.setWeight(75)
        font.setBold(True)
        self.label_6.setFont(font)
        self.label_6.setObjectName("label_6")
#        self.pushButton_4 = QtGui.QPushButton(Dialog)
#        self.pushButton_4.setGeometry(QtCore.QRect(640,370,31,23))
#        self.pushButton_4.setObjectName("pushButton_4")
#        self.label_7 = QtGui.QLabel(Dialog)
#        self.label_7.setGeometry(QtCore.QRect(240,370,381,16))
#        font = QtGui.QFont()
#        font.setWeight(75)
#        font.setBold(True)
#        self.label_7.setFont(font)
#        self.label_7.setObjectName("label_7")
        self.label_8 = QtGui.QLabel(Dialog)
        self.label_8.setGeometry(QtCore.QRect(20,60,46,14))
        self.label_8.setObjectName("label_8")
        self.label_10 = QtGui.QLabel(Dialog)
        self.label_10.setGeometry(QtCore.QRect(30,160,171,16))
        font = QtGui.QFont()
        font.setPointSize(9)
        font.setWeight(75)
        font.setBold(True)
        self.label_10.setFont(font)
        self.label_10.setObjectName("label_10")
        self.label_11 = QtGui.QLabel(Dialog)
        self.label_11.setGeometry(QtCore.QRect(40,250,171,16))
        font = QtGui.QFont()
        font.setPointSize(9)
        font.setWeight(75)
        font.setBold(True)
        self.label_11.setFont(font)
        self.label_11.setObjectName("label_11")
        self.label_9 = QtGui.QLabel(Dialog)
        self.label_9.setGeometry(QtCore.QRect(40,270,101,16))
        font = QtGui.QFont()
        font.setPointSize(9)
        font.setWeight(75)
        font.setBold(True)
        self.label_9.setFont(font)
        self.label_9.setObjectName("label_9")
      
        #fn = QFileDialog.getOpenFileName()
        #filename=QFileDialog.getOpenFileName("C:\\", "*.py", self, "FileDialog")
 #       

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton.setText(QtGui.QApplication.translate("Dialog", "Delete From Backup", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_2.setText(QtGui.QApplication.translate("Dialog", "Cancel", None, QtGui.QApplication.UnicodeUTF8))
#        self.label.setText(QtGui.QApplication.translate("Dialog", "Today (Now)", None, QtGui.QApplication.UnicodeUTF8))
#        self.comboBox.addItem(QtGui.QApplication.translate("Dialog", "Date / Time Selection...", None, QtGui.QApplication.UnicodeUTF8))
        self.label_2.setText(QtGui.QApplication.translate("Dialog", "Delete Files from Backup :", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_3.setText(QtGui.QApplication.translate("Dialog", "?", None, QtGui.QApplication.UnicodeUTF8))
        self.label_3.setText(QtGui.QApplication.translate("Dialog", "1 - Select a file from the list", None, QtGui.QApplication.UnicodeUTF8))
 #       self.label_4.setText(QtGui.QApplication.translate("Dialog", "2 - Select the date from which you", None, QtGui.QApplication.UnicodeUTF8))
 #       self.label_5.setText(QtGui.QApplication.translate("Dialog", "3 - Select a directory in which ", None, QtGui.QApplication.UnicodeUTF8))
        self.label_6.setText(QtGui.QApplication.translate("Dialog", "2 - Click on \"Delete\"", None, QtGui.QApplication.UnicodeUTF8))
#        self.pushButton_4.setText(QtGui.QApplication.translate("Dialog", "...", None, QtGui.QApplication.UnicodeUTF8))
#        self.label_7.setText(QtGui.QApplication.translate("Dialog", "Select the Directory in which your files will be recovered ...", None, QtGui.QApplication.UnicodeUTF8))
 #       self.label_10.setText(QtGui.QApplication.translate("Dialog", " want your file to be recovered", None, QtGui.QApplication.UnicodeUTF8))
 #       self.label_11.setText(QtGui.QApplication.translate("Dialog", "your want your recovered ", None, QtGui.QApplication.UnicodeUTF8))
 #       self.label_9.setText(QtGui.QApplication.translate("Dialog", "files to appear", None, QtGui.QApplication.UnicodeUTF8))


def getSelected():
    import InterfaceExt
    truc = listv.selectedIndexes()
    nom="null"
    for item in truc:
        #print listmagic[item.row()]
        #print InterfaceRB.getTimesToRecover(listmagic[item.row()])
        nom = str(listmagic[item.row()])
        zz = InterfaceRB.getTimesToRecover(listmagic[item.row()])
        #ui.comboBox.clear()
        #ui.comboBox.addItem("Date / Time Selection...")
        #ui.comboBox.addItem(zz[0])
    listDel = []
    listDel.append(nom)
    list = Xml.retrieveInfoXml('C:\\Documents and Settings\\All Users\\Application Data\\EBT\\EBT-setup.xml', 'BackupDir')
    listBackup=os.listdir(list[0])
    #listmagic=[]
    for elements in listBackup:
        pattern = '(xdelta$|acl$)'
        if (re.search(pattern, elements)):
            xx=elements.split('_')
            if xx[0]==nom:
                listDel.append(elements)
    InterfaceExt.deleteFile(listDel)
    backupFile = Xml.retrieveAllXml('C:\\Program Files\\EasyBackupTool\\backupFile.xml')
    backupTimes = Xml.retrieveAllXml('C:\\Program Files\\EasyBackupTool\\backupTimes.xml')
    for element in backupFile:
        if os.path.basename(element)==nom:
            print "Jai trouveeeeeeee"
            backupFile.remove(element)
    Xml.createXml('C:\\Program Files\\EasyBackupTool\\backupFile.xml','ref_ID', backupFile)
    for elem in backupTimes:
        xy=elem.split('_')
        if xy[0]==nom:
            backupTimes.remove(elem)
    Xml.createXmlBP('C:\\Program Files\\EasyBackupTool\\backupTimes.xml', 'lastBackupTime', backupTimes)
    return
    
    
if __name__ == "__main__":
    import sys, Xml, InterfaceRB, os, re
    
    from PyQt4.QtCore import *
    from PyQt4.QtGui import *
    from PyQt4 import QtCore, QtGui 
    
    #from Qt import *
#########
    app = QtGui.QApplication(sys.argv)
    
    Dialog = QtGui.QDialog()
    ui = Ui_Dialog()
    
    list = Xml.retrieveInfoXml('C:\\Documents and Settings\\All Users\\Application Data\\EBT\\EBT-setup.xml', 'BackupDir')
    listBackup=os.listdir(list[0])
    listmagic=[]
    for elements in listBackup:
        pattern = '(xdelta$|acl$)'
        if not(re.search(pattern, elements)):
            listmagic.append(elements)
        
    #print listmagic        
            
    model = QtGui.QDirModel()
    
    
    
    #tree = QtGui.QTreeView(Dialog)
    #tree.setModel(model)

##########


 #   tree.setRootIndex(model.index(list[0]))
    
    listv = QtGui.QListView(Dialog)
    listv.setModel(model)
    listv.setViewMode(QtGui.QListView.IconMode)
    listv.setRootIndex(model.index(list[0]))
    #listv.setRootIndex(model.index('C:\\'))
    size = QtCore.QSize(75,75)
    listv.setGridSize(size)
    listv.isWrapping()
    listv.setSelectionRectVisible(True)
    listv.setUniformItemSizes(True)
    listv.setMovement(QtGui.QListView.Snap)
    
    #hihi = QFile()
    #test = QListViewItem(listv)
    
    #listv.remove(0)
    #hehe = QListViewItem(listv)
    #lvi = QtGui.QListView.QListViewItem()
####################   
    ui.setupUi(Dialog, listv)
    Dialog.show()
   # ui.listView.show()
   
    #app.connect(ui.listView, QtCore.SIGNAL("clicked(QModelIndex)"),getSelected)
    #app.connect(ui.pushButton_4, QtCore.SIGNAL("clicked()"), directoryRecovery)
    app.connect(ui.pushButton_2, QtCore.SIGNAL("clicked()"), Dialog.close)
    app.connect(ui.pushButton, QtCore.SIGNAL("clicked()"), getSelected)
    
    #tree.show()
    sys.exit(app.exec_())
#########################